<?php
/**
 * Copyright (c) 2019. Supefun<supefun@163.com> All rights reserved.
 */

namespace app\smart\controller;

use app\smart\model\Poetry;
use think\Controller;

/**
 * 小学古诗80首
 *
 * Class XiaoGuShi
 * @package app\smart\controller
 */

class Gushi extends Controller
{
    public function index($id = 0, $puzzle = 0)
    {
        $data = file_get_contents(__DIR__.'/../data/gushi80.json');

        $data = json_decode($data, true);

        $id = intval($id);
        if(isset($data[$id])){
            $poetry = new Poetry($data[$id]);
            $poetry->draw($puzzle) ;
        }else{
            exit('no Id');
        }
    }

    public function json()
    {
        header("content: application/json;chartset=uft-8");
        echo 'var data='.file_get_contents(__DIR__.'/../data/gushi80.json');
    }

    public function test()
    {
        return $this->fetch();
    }
}
